/*******************************************************************************
 Jimm - Mobile Messaging - J2ME ICQ clone
 Android version
 Copyright (C) 2003-11  Jimm Project

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ********************************************************************************
 File: src/jimm/app/LicenseActivity.java
 Version: ###VERSION###  Date: ###DATE###
 Author(s): Ashikhmin Kirill
 *******************************************************************************/
package org.jimm.app;

import org.jimm.app.util.Func;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

public class LicenseActivity  extends Activity {
	
	public static final String LOG_TAG = "Jimm:LicenseActivity";
	public static boolean Lic;
	public static String lang;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.license);	
	
	
	
	
    final String[] mLang = {
		"en",
		"ru"
};
    // TODO функция проверки языка из массива через чикл  (lang[].lenght). Пропускает строку через мароверку и возвращает boolean значение. передавать строку и массив.
    WebView License = (WebView) findViewById(R.id.License);
    String lang = getResources().getConfiguration().locale.getLanguage();
    
    
   
    

    boolean checkLang=Func.CheckMass(lang, mLang);
    Log.i(LOG_TAG, "if !"+lang+checkLang+"!");
    if (checkLang) {
    License.loadUrl("http://jimm.boomik.ru/Lic_"+lang+".html");
    Log.i(LOG_TAG, "if !"+lang+"!"); } 
    else {
    License.loadUrl("http://jimm.boomik.ru/Lic_en.html");
    Log.i(LOG_TAG, "else !"+lang+"!");}

    //License.loadData("http://jimm.boomik.ru/Lic_Ru.html", mimeType, encoding);
	
	//final TextView LicenseText = (TextView)findViewById(R.id.LicenseText);
	final Button LicenseBut1 = (Button)findViewById(R.id.LicenseBut1);
	final Button LicenseBut2 = (Button)findViewById(R.id.LicenseBut2);
	
	//LicenseText.setText(R.string.LicenseText);	
	LicenseBut1.setText(R.string.LicenseYes);
	LicenseBut2.setText(R.string.Exit);
	
	LicenseBut1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        	finish();
        	SavePref(true);
        	startActivity(new Intent(LicenseActivity.this, InitializeActivity.class));
        }
    });
	

		LicenseBut2.setOnClickListener(new View.OnClickListener() {
	        public void onClick(View v) {
	        	SavePref(false);
	        	JimmApplication.closeApp(); 
	        	finish();
	        }
	    });	
	} 
	

	private void SavePref(boolean b) {
		SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("License",b);
        editor.commit();
        Log.i(LOG_TAG, "License Set "+b);		
	}
}
